﻿using UnityEngine;

/// <summary>
/// 浮点型范结构
/// </summary>
public struct RangeFloat
{
    public float min { get; private set; }
    public float max { get; private set; }

    /// <summary>
    /// 返回随机值 (min, max)
    /// </summary>
    public float random => UnityEngine.Random.Range(min, max);

    /// <summary>
    /// 返回最大值最小值之间的差值
    /// </summary>
    public float difference => max - min;

    public RangeFloat(float min, float max)
    {
        this.min = max >= min ? min : max;
        this.max = max >= min ? max : min;
    }

    /// <summary>
    /// 收束取值范围
    /// </summary>
    public float Clamp(float value)
    {
        return Mathf.Clamp(value, min, max);
    }
}